package com.nttuyen.xmppdemo;

import org.jivesoftware.smack.Chat;
import org.jivesoftware.smack.ConnectionConfiguration;
import org.jivesoftware.smack.MessageListener;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.packet.Message;

/**
 * Hello world!
 *
 */
public class App {
    public static void main( String[] args ) {
        System.out.println( "Hello World!" );
        ConnectionConfiguration config = new ConnectionConfiguration("talk.google.com", 5222, "googlemail.com");
        
        XMPPConnection connection = new XMPPConnection(config);
        try {
            connection.connect();
            connection.login("test@nttuyen.com", "adminpass");
            Chat chat = connection.getChatManager().createChat("nttuyen87@gmail.com", new MessageListener() {
                public void processMessage(Chat chat, Message msg) {
                    System.out.println("Receive message: " + msg);
                    System.out.println("From: " + msg.getFrom());
                    System.out.println("Subject: " + msg.getSubject());
                    System.out.println("Body: " + msg.getBody());
                }
            });
            while(true) {
                chat.sendMessage("Demo phat xem no the nao :D");
                Thread.sleep(5000);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
